import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl

mpl.rcParams["axes.unicode_minus"] = False

# 柱高信息
Y = [0.57, 1.2, 2.09, 3.63, 5.38, 5.33, 5.33]
Y2 = [0.56, 1.11, 1.96, 2.77, 2.61, 2.78, 2.84]
Y3 = [0.53, 1.07, 1.77, 2.10, 2.22, 2.28, 2.20]

X = np.arange(len(Y))

bar_width = 0.3
tick_label = ['64', '128', '256', '512', '1024', '2048', '4016']

fig = plt.figure()
ax1 = fig.add_subplot(111)
axes = plt.gca()
axes.set_ylim([0, 5.6])
ax1.tick_params(labelsize=14)  # 刻度字体大小13
# 绘制柱状图
# p1=ax1.bar(X, Y, bar_width - 0.02, align="center", color="lightcoral",hatch='|')
p1 = ax1.bar(X + bar_width, Y, bar_width - 0.05, align="center", color='white', edgecolor='lightcoral', hatch='\\\\')
p2 = ax1.bar(X + bar_width * 2, Y2, bar_width - 0.05, color='white', edgecolor="sienna", align="center", hatch='//')
p3 = ax1.bar(X + bar_width * 3, Y3, bar_width - 0.05, color='white', edgecolor="darkcyan", align="center", hatch='++')

ax = plt.gca()
ax.tick_params()
# ax.grid()
plt.ylabel("Goodput (Gbps)", fontsize=14)
plt.xlabel("Packet size (bytes)", fontsize=14)
# plt.title()
plt.axhline(y=1, color='lightgray', ls=':', linewidth=1)
plt.axhline(y=2, color='lightgray', ls=':', linewidth=1)
plt.axhline(y=3, color='lightgray', ls=':', linewidth=1)
plt.axhline(y=4, color='lightgray', ls=':', linewidth=1)
plt.axhline(y=5, color='lightgray', ls=':', linewidth=1)
plt.xticks(X + bar_width * 2, tick_label)
# 显示图例
# plt.legend(fontsize=14)
plt.legend([p1, p2, p3], ['Baseline', 'Packet', 'Flow', ], fontsize=14, frameon=False, loc=2)
plt.savefig('goodput_of_ids.pdf', bbox_inches='tight')
plt.show()
